<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ page import="com.zkingsoft.constance.SystemConstance"%>
<%@ page import="com.zkingsoft.util.WebUtil"%>
<%
	String login_plat = String.valueOf(WebUtil.getSessionAttribute(SystemConstance.LOGIN_PLAT));
	String isHotelLogin = "false";
	if(SystemConstance.PLAT_HOTEL.equals(login_plat)) {
		isHotelLogin = "true";
	}
	
	String isFactoryLogin = "false";
	if(SystemConstance.PLAT_FACTORY.equals(login_plat)) {
		isFactoryLogin = "true";
	}
	
	String isCompanyLogin = "false";
	if(SystemConstance.PLAT_COMPANY.equals(login_plat)) {
		isCompanyLogin = "true";
	}
%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/plugin/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>
</head>
<body>
	<div class="ibox-content">
		<form class="form-horizontal" id="dataform" onsubmit="javascripr:return false;">
			<div class="form-group">
				<label class="col-sm-2 control-label">酒店 </label>
				<div class="col-sm-4">
					<select class="form-control autoFull select2" dataType="*" nullmsg="酒店不能为空" 
						data-url="${path}/admin/linHotel/getAllHotels"	 
						data-value="hotelId"
						data-filed="hotelName"
						data-def="${obj.hotelId}"  
						name="hotelId">
					</select>
				</div>
				<label class="col-sm-2 control-label">订单状态 </label>
				<div class="col-sm-4">
					<select class="form-control select2" name="orderState" dataType="*" nullmsg="订单状态不能为空">
						<option <c:if test="${obj.orderState eq 1}"> selected="selected"</c:if> value="1">已创建</option>
						<option <c:if test="${obj.orderState eq 2}"> selected="selected"</c:if> value="2">入库运输</option>
						<option <c:if test="${obj.orderState eq 3}"> selected="selected"</c:if> value="3">已入库</option>
						<option <c:if test="${obj.orderState eq 4}"> selected="selected"</c:if> value="4">已出库</option>
						<option <c:if test="${obj.orderState eq 5}"> selected="selected"</c:if> value="5">出库运输</option>
						<option <c:if test="${obj.orderState eq 6}"> selected="selected"</c:if> value="6">已验收</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">总数量 <span
					class="text-danger">*</span>
				</label>
				<div class="col-sm-4">
					<input type="number" class="form-control" name="orderTotalNum" readonly="readonly"
						maxLength="9" dataType="n1-9"
						oninput="if(value.length>9)value=value.slice(0,9)"
						value="<c:out value="${obj.orderTotalNum }"></c:out>"
						nullmsg="总数量不能为空">
				</div>
				<label class="col-sm-2 control-label">总价格 <span
					class="text-danger">*</span>
				</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" name="orderTotalPrice" readonly="readonly"
						maxLength="13" dataType="/^[0-9]{1,8}(\.[0-9]{1,2})?$/"
						<%if("true".equals(isFactoryLogin) ) { %>
						value="<fmt:formatNumber type="number" value="${obj.orderTotalPrice }" pattern="0.00" maxFractionDigits="2"/>"
						<%} else if("true".equals(isCompanyLogin)) { %>
						<c:if test="${orderType eq 'factory'}">
						value="<fmt:formatNumber type="number" value="${obj.orderTotalPrice }" pattern="0.00" maxFractionDigits="2"/>"
						</c:if>
						<c:if test="${orderType eq 'hotel'}">
						value="<fmt:formatNumber type="number" value="${obj.orderRealPrice }" pattern="0.00" maxFractionDigits="2"/>"
						</c:if>
						<%} else { %>
						value="<fmt:formatNumber type="number" value="${obj.orderRealPrice }" pattern="0.00" maxFractionDigits="2"/>"
						<%} %>
						nullmsg="总价格不能为空">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">订单备注 </label>
				<div class="col-sm-10">
					<input type="text" class="form-control" name="orderRemark" readonly="readonly"
						maxLength="1000" dataType="s1-1000" ignore="ignore"
						value="<c:out value="${obj.orderRemark }"></c:out>"
						nullmsg="订单备注不能为空">
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-10" style="margin: 0 auto; float: initial;">
					<table id="mgrid">
						<thead>
							<tr>
								<th data-formatter="MGrid.indexfn" data-align="center"
									data-width="30px">序号</th>
								<th data-field="typeName" data-width="30%">布草名称</th>
								<th data-field="typeUnit" data-width="20%">单位</th>
								<th data-field="typePrice" data-width="20%" data-formatter="toPriceInput">单价（元）</th>
								<th data-field="detailsNum" data-width="20%">数量</th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
			<div class="form-group ">
				<div class="col-sm-12 text-center">
					<a class="btn btn-danger radius" href="javascript:;"
						onclick="MTools.closeForm()"><i class="fa fa-close"></i> 关闭</a>
				</div>
			</div>
		</form>
	</div>
</body>
<script type="text/javascript"
	src="${path }/resource/js/systools/MJsBase.js"></script>
<script type="text/javascript">
	function toPriceInput(value, row, index) {
		if("<%=isFactoryLogin%>" == 'true') {
			return (row.detailsTotalPrice/row.detailsNum).toFixed(2);
		} else if("<%=isCompanyLogin%>" == 'true'){
			if('${orderType}' == 'factory') {
				return (row.detailsTotalPrice/row.detailsNum).toFixed(2);
			} else {
				return (row.detailsRealPrice/row.detailsNum).toFixed(2);
			}
		} else {
			return (row.detailsRealPrice/row.detailsNum).toFixed(2);
		}
	}
</script>
<script type="text/javascript">
	
	MTools.autoFullSelect();
	$(".select2").select2();
	
	var myForm = MForm.initForm({
		invokeUrl : "${path}/admin/linOrder/addOrModify",
		afterSubmit : function() {
			parent.myGrid.serchData();
		},
	});

	var myGrid;
	
	$('select[name="hotelId"]').select2("enable", false);
	$('select[name="hotelId"]').next('span').children('span').children('span').children('span').css("background-color", "#eee");
	$('select[name="orderState"]').select2("enable", false);
	$('select[name="orderState"]').next('span').children('span').children('span').children('span').css("background-color", "#eee");

	$(function() {
		myGrid = MGrid.initGrid({
			url : "${path}/admin/linOrderDetails/getOrderDetails?orderId=${obj.orderId }",
			showColumns : false,
			showToggle : false,
			showRefresh : false,
			checkboxHeader : false,
			formatNoMatches : function() {
				return '';
			},
			pagination : false
		});

	});
	
</script>
</body>
</html>